package com.android.diceroll

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
//        程序默认创建
//        程序开始
        val diceRoll:Button = findViewById(R.id.button)
        diceRoll.setOnClickListener { mainListenClick() }
    }

    @SuppressLint("Range", "SetTextI18n")
    private fun mainListenClick() {
        val diceFace = DiceRoll(10)
        val result = diceFace.roll()
        val luckyNum = 2
        val hide = 0f
        val show = 100f
        val wife: ImageView = findViewById(R.id.imageView2)
        val luckyText:TextView = findViewById(R.id.textView2)
        when (result) {
            luckyNum -> {
                luckyText.text = "获得五星刻晴"
                wife.alpha = show
            }
            1 -> {
                luckyText.text = "下次一定"
                wife.alpha = hide
            }
            3 -> {
                luckyText.text = "快啦快啦"
                wife.alpha = hide
            }
            4 -> {
                luckyText.text = "不能这么非吧"
                wife.alpha = hide
            }
            5 -> {
                luckyText.text = "还差一发648"
                wife.alpha = hide
            }
            6 -> {
                luckyText.text = "歪了七七？"
                wife.alpha = hide
            }
            7 -> {
                luckyText.text = "记住！欧非守恒"
                wife.alpha = hide
            }
            8 -> {
                luckyText.text = "酋长你还是回来吧"
                wife.alpha = hide
            }
            9 -> {
                luckyText.text = "单手剑5星冰系"
                wife.alpha = hide
            }
            10 -> {
                luckyText.text = "不要啊扬哥"
                wife.alpha = hide
            }
        }
    }

    class DiceRoll(private val num:Int){
        fun roll(): Int {
            return (1..num).random()
        }
    }
}